# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=dia
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.97.0.r2610.g9fcced5ed
pkgrel=12
pkgdesc="A gtk+ based diagram creation program (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://gitlab.gnome.org/GNOME/dia'
msys2_references=(
  "cpe: cpe:/a:dia:dia"
  "cpe: cpe:/a:gnome:dia"
)
msys2_ignore_vulnerabilities=(
  "CVE-2006-2453" # fixed long ago in https://gitlab.gnome.org/GNOME/dia/-/commit/7382137b25dfad4bc350
)
license=('spdx:GPL-2.0-or-later')
depends=(
  "${MINGW_PACKAGE_PREFIX}-glib2"
  "${MINGW_PACKAGE_PREFIX}-gtk3"
  "${MINGW_PACKAGE_PREFIX}-libxml2"
  "${MINGW_PACKAGE_PREFIX}-graphene"
  "${MINGW_PACKAGE_PREFIX}-cairo"
  "${MINGW_PACKAGE_PREFIX}-zlib"
  "${MINGW_PACKAGE_PREFIX}-libxslt"
  "${MINGW_PACKAGE_PREFIX}-poppler"
)
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-desktop-file-utils"
             "${MINGW_PACKAGE_PREFIX}-gtk-update-icon-cache"
             "${MINGW_PACKAGE_PREFIX}-gettext-tools"
             "git")
_commit="9fcced5edb5a10faae5e5965658aec9732cd7f5a"
source=("${_realname}"::"git+https://gitlab.gnome.org/GNOME/dia.git#commit=${_commit}")
sha256sums=('d922dff53a4938208d6c4c4741b4fc3e9283b75d35c93d456c7616ba2e114528')

pkgver() {
  cd "${_realname}"

  git describe --long "${_commit}" | sed 's/DIA_//;s/_/./g' | sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/^v//g'
}

prepare() {
  cd "${_realname}"
}

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  if [[ $MINGW_PACKAGE_PREFIX == *-clang-* ]]; then
    CFLAGS+=" -Wno-error=incompatible-pointer-types-discards-qualifiers"
    CXXFLAGS+=" -Wno-error=incompatible-pointer-types-discards-qualifiers"
  fi

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/meson setup \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      --buildtype=plain \
      -Dcpp_std=gnu++20 \
      -Ddoc=false \
      ../${_realname}

  ${MINGW_PREFIX}/bin/meson compile
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/meson install
  rm "${pkgdir}${MINGW_PREFIX}"/lib/dia/*.dll.a

  install -Dm644 "${srcdir}/${_realname}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
